/* Guile-GCC
   Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>

   This file is part of Guile-GCC.

   Guile-GCC is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Guile-GCC is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Guile-GCC.  If not, see <http://www.gnu.org/licenses/>.  */

#include <gcc-plugin.h>

#include <plugin.h>
#include <cpplib.h>
#include <tree.h>

#include <cgraph.h>
#include <gimple.h>

#include <ggcc-utils.h>

#define MAKE_CGRAPH_NODE_ACCESSOR(field, to_scm)			\
  SCM_DEFINE (ggcc_cgraph_node_ ## field, "%cgraph-node-" STRINGIFY (field), \
	      1, 0, 0,							\
	      (SCM pointer),						\
	      "Return the " STRINGIFY (field) " of @var{pointer}.")	\
  {									\
    return to_scm (((struct cgraph_node *) SCM_POINTER_VALUE (pointer))	\
		   ->field);						\
  }

MAKE_CGRAPH_NODE_ACCESSOR (next, ggcc_from_pointer)
MAKE_CGRAPH_NODE_ACCESSOR (decl, ggcc_from_pointer)
MAKE_CGRAPH_NODE_ACCESSOR (callees, ggcc_from_pointer)
MAKE_CGRAPH_NODE_ACCESSOR (callers, ggcc_from_pointer)
MAKE_CGRAPH_NODE_ACCESSOR (analyzed, scm_from_bool)

#define MAKE_CGRAPH_EDGE_ACCESSOR(field, to_scm)			\
  SCM_DEFINE (ggcc_cgraph_edge_ ## field, "%cgraph-edge-" STRINGIFY (field), \
	      1, 0, 0,							\
	      (SCM pointer),						\
	      "Return the " STRINGIFY (field) " of @var{pointer}.")	\
  {									\
    return to_scm (((struct cgraph_edge *) SCM_POINTER_VALUE (pointer))	\
		   ->field);						\
  }

MAKE_CGRAPH_EDGE_ACCESSOR (callee, ggcc_from_pointer)
MAKE_CGRAPH_EDGE_ACCESSOR (caller, ggcc_from_pointer)
MAKE_CGRAPH_EDGE_ACCESSOR (next_callee, ggcc_from_pointer)
MAKE_CGRAPH_EDGE_ACCESSOR (next_caller, ggcc_from_pointer)
MAKE_CGRAPH_EDGE_ACCESSOR (call_stmt, ggcc_from_pointer)


/* The initialization routing for the (gcc cgraph) module.  It is called
   directly from Scheme.  */

void
ggcc_init_cgraph (void)
{
#include "cgraph.x"
}
